package com.csproj.system.service;

import com.csproj.basic.BasicService;
import com.csproj.basic.service.PathService;
import com.csproj.system.domain.Language;
import com.csproj.system.repository.LanguageRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class LanguageService extends BasicService<Language> {
    private final Logger log;
    private final LanguageRepository languageRepository;

    public LanguageService(LanguageRepository languageRepository) {
        this.languageRepository = languageRepository;
        log = LoggerFactory.getLogger(LanguageService.class);
    }

    public void setLanguage(String lang) {
        this.languageRepository.updateNotDefault();
        Language language;
        switch (lang) {
            case "zh":
                language = this.languageRepository.findByName(lang);
                language.setDefault(true);
                this.languageRepository.save(language);
                break;
            case "en":
                language = this.languageRepository.findByName(lang);
                language.setDefault(true);
                this.languageRepository.save(language);
                break;
            case "pu":
                language = this.languageRepository.findByName(lang);
                language.setDefault(true);
                this.languageRepository.save(language);
                break;
        }
    }
}
